<template>
  <view class='jianding'>
    <view class="title sticky-tabs">{{obj.assetsName}}————鉴定资产</view>
    <u-gap height="10" bgColor="#f5f5f5"></u-gap>
    <view>
      <u-cell-group>
        <u-cell title="编号" :value="obj.assetsNo"></u-cell>
        <u-cell title="鉴定金额" :value="obj.price"></u-cell>
        <u-cell title="分配人" :value="obj.distributionUser"></u-cell>
        <u-cell title="存放地：" :value="obj.deposit"></u-cell>
        <u-cell title="创建时间：" :value="obj.createTime"></u-cell>
        <u-cell title="鉴定人" isLink @click="selectHanlder">
          <text slot="value" class="u-slot-value">{{formStata.creatUserName}}</text>
        </u-cell>
        <u-cell title="备注">
          <view slot="value" style="width: 50%;">
            <u-input v-model="formStata.remarks" border="none" placeholder="请输入" inputAlign="right">
            </u-input>
          </view>
        </u-cell>
        <u-cell title="图片上传" :value="obj.deposit">
          <view slot="value">
            <uploadFile @success="success" @deleteHanlder="delHanlder" :maxCount="999"></uploadFile>
          </view>
        </u-cell>
      </u-cell-group>
    </view>
    <view class="btn">
      <view class="save" @click="submit">保存</view>
    </view>
    <!-- 基础用法选人 -->
    <template v-if="show">
      <u-popup height="90%" mode="bottom" :show="show" @close="show=false">
        <tree @onchange="onchange" :type='treeType'></tree>
      </u-popup>
    </template>
  </view>
</template>

<script>
import tree from "@/components/search/tree/tree.vue"
export default {
  components: {
    tree
  },
  data() {
    return {
      obj: {},
      show: false,
      treeType: 0,
      formStata: {
        no: "",
        wareID: "",
        assetsID: "",
        assetsNo: "",
        assetsName: "",
        creatUser: "",
        creatUserName: "",
        file: [],
        remarks: "",
        objectID: "",
        isDelete: true,
        createTime: "",
        createUserID: "",
        updateTime: "",
        order: 0
      }

    };
  },
  onLoad(e) {

    this.obj = JSON.parse(e.item)
    this.obj.distributionUser = this.obj.distributionUser ? JSON.parse(this.obj.distributionUser).map((x) => x.name).join(',') : ''
  },

  methods: {
    // 打开选人
    selectHanlder() {
      this.treeType = 1
      this.show = true
    },
    onchange(user, val) {

      this.show = false
      this.formStata.creatUser = val.userId
      this.formStata.creatUserName = user
    },

    // 图片上传
    success(file) {
      this.formStata.file = file
    },
    delHanlder(index) {
      this.formStata.file = this.formStata.file.splice(index, 1)
    },

    submit() {
      if (!this.formStata.creatUserName) return this.$u.toast('请选择鉴定人')
      if (!this.formStata.remarks) return this.$u.toast('请输入备注')
      if (this.formStata.file.length === 0) return this.$u.toast('请上传附件')

      var _this = this
      const data = {
        no: '',
        wareID: this.obj.objectID,
        assetsID: this.obj.assetsID,
        assetsNo: this.obj.assetsNo,
        assetsName: this.obj.assetsName,
        creatUser: this.formStata.creatUser,
        creatUserName: this.formStata.creatUserName,
        file: JSON.stringify(this.formStata.file),
        remarks: this.formStata.remarks,
        objectID: this.obj.objectID,
        isDelete: this.obj.isDelete,
        createTime: this.obj.createTime,
        createUserID: this.obj.createUserID,
        updateTime: this.obj.updateTime,
        order: this.obj.order
      }
      wx.showModal({
        title: '提示',
        content: '是否确认提交？',
        success(v) {

          //   return
          _this.$u.api.Appraisal(data).then(res => {
            if (res.flag) {
              _this.$u.toast('提交成功');
              uni.navigateBack();

            }
          })
        }
      })
    }
  }
};
</script>

<style scoped lang="scss">
.jianding {
  background: #fff;

  .title {
    height: 100rpx;
    line-height: 100rpx;
    font-size: 34rpx;
    text-align: center;
  }
  .deposit {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    .deposit-btn {
      width: 100rpx;
      margin-left: 10rpx;
    }
  }
  .btn {
    font-size: 30rpx;
    display: flex;
    justify-content: space-around;
    background: #f5f5f5;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;

    .save {
      width: 100%;
      height: 88rpx;
      background-color: #0d6fb8;
      color: #ffffff;
      text-align: center;
      line-height: 88rpx;
    }
  }
}
.sticky-tabs {
  z-index: 990;
  position: sticky;
  top: var(--window-top);
  background-color: #fff;
}
</style>
